<template>
    <div class="seat-container">
        <div class="film-info">
            <h1>{{info.filmName}}</h1>
            <span>{{info.date}}</span>
            <span>{{info.version}}</span>
        </div>
        <div class="seat-info">
            <div class="hall">{{info.hall}}</div>
            <div class="select-seat">
                <div class="number">
                    <span v-for="i in n" :key="i">{{i}}</span>
                </div>
                <div class="seat">
                    <div class="sn" v-for="j in n" :key="j">
                        <span :class="info['seat'].indexOf(`${j}排${k}座`)==-1?' ':'seat-active'" @click="getSeat(j,k)" v-for="k in m" :key="k"></span>
                    </div>
                </div>
            </div>
            <div class="explain">
                <span></span>可选
                <span></span>不可选
                <span></span>已选
            </div>
        </div>
        <div class="selected">
            <div class="recommend" v-if="flag==false">
                <span>推荐座位</span>
                <span>1人</span>
                <span>2人</span>
                <span>3人</span>
                <span>4人</span>
                <span>5人</span>
            </div>
            <div class="selected-seat" v-else>
                <div class="ss" v-for="(item,i) in info['seat']" :key="i">
                    <div class="sss"></div>
                    <span>{{item}}</span>
                </div>
            </div>
        </div>
        <div class="btn">
            <mt-button :class="flag==true?'btn-active':' '" type="danger" size="large" @click="getComfirm">{{flag==true?'确认':'请先选择'}}</mt-button>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            info:JSON.parse(localStorage.getItem('seat')),
            n:5,
            m:10,
            row:0,
            colum:0,
            flag:false
        }
    },
    created(){
        this.getInfo()
        this.$store.commit("changeTitle",this.info.cinemaName);
        if(this.info['seat'].length==0){
            this.flag=false;
        }
        else{
            this.flag=true;
        }
    },
    methods:{
        getInfo(){
            //  this.info = JSON.parse(localStorage.getItem('seat'))
             console.log(this.info)
        },
        getSeat(r,c){
            this.row=r;
            this.colum=c;
            // localStorage.setItem('seat', JSON.stringify(select))
            // if(!this.info['seat']){
            //     this.info['seat']=[]
            // }
            if(this.info['seat'].indexOf(`${r}排${c}座`)==-1){
                this.info['seat']=this.info['seat'].concat(`${r}排${c}座`)
            }else{
                this.info['seat'].some((item,index)=>{
                    console.log(item)
                    console.log(index)
                    if(item==`${r}排${c}座`){
                        console.log(item==`${r}排${c}座`)
                        this.info['seat'].splice(index,1)
                        return true
                    }
                })
                // this.info['seat']=this.info['seat'].concat(`${r}排${c}座`)
            }
            // console.log(this)
            localStorage.setItem('seat',JSON.stringify(this.info))
            console.log(this.info)
            if(this.info['seat'].length==0){
                this.flag=false;
            }
            else{
                this.flag=true;
            }
        },
        getComfirm(){
            if(this.$cookies.get('accoutCookie')){
                let val = this.$cookies.get('accoutCookie')
                let user = JSON.parse(localStorage.getItem(val) || '[]')
                user.push(this.info)
                localStorage.setItem(val,JSON.stringify(user))
                this.$router.push({name:'order', params:{id:val}})
            }else{
                this.$router.push({path:'/me'})
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.seat-container{
    .film-info{
        font-size: 15px;
        color: rgb(129, 129, 129);
        border-bottom: 1px solid lightgray;
        margin: 20px 15px;
        padding-bottom: 15px;
        h1{
            color: black;
            font-size: 18px;
        }
    }
    .seat-info{
        width: 100%;
        height: 320px;
        background-color: rgb(241, 240, 240);
        box-shadow: 0 0 2px rgb(182, 182, 182);
        .hall{
            margin: 0 auto;
            width: 200px;
            height: 25px;
            background-color: rgb(223, 223, 223);
            border-radius: 0 0 100% 100%;
            text-align: center;
            color: rgb(138, 138, 138);
        }
        .select-seat{
            margin-top: 50px;
            display: flex;
            .number{
                height: 150px;
                width: 10px;
                align-items: center;
                display: flex;
                flex-direction: column;
                justify-content: space-around;
                font-size: 10px;
                background-color: rgb(223, 223, 223);
            }
            .seat{
                width: 100%;
                height: 150px;
                margin: 0 10%;
                .sn{
                    height: 30px;
                    display: flex;
                    justify-content: space-around;
                    span{
                        display: block;
                        width: 25px;
                        height: 25px;
                        background-color: #fff;
                        border: 1px solid rgb(200, 200, 201);
                        border-radius: 30% 30% 0 0;
                    }
                    .seat-active{
                        background-color: green;
                    }
                }
            }
        }
        .explain{
            display: flex;
            height: 25px;
            margin-top: 40px;
            justify-content: center;
            align-items: center;
            span{
                display: block;
                width: 25px;
                height: 25px;
                border: 1px solid rgb(200, 200, 201);
                border-radius: 30% 30% 0 0;
            }
            span:nth-child(1){
                background-color: #fff;
                margin:0 3px 0 0;
            }
            span:nth-child(2){
                background-color: red;
                margin:0 3px 0 10px;
            }
            span:nth-child(3){
                background-color: green;
                margin:0 3px 0 10px;
            }                        
        }
    }
    .selected{
        .recommend{
            width: 100%;
            display: flex;
            justify-content: space-around;
            align-items: center;
            margin-top: 15px;
            span{
                display: block;
            }
            span:nth-child(1){
                font-size: 14px;
            }
            span:nth-child(n+2){
                font-size: 13px;
                width: 50px;
                height: 30px;
                line-height: 30px;
                text-align: center;
                border: 1px solid rgb(200, 200, 201);
            }
        }
        .selected-seat{
            display: flex;
            padding-left:15px;
            margin-top: 15px;
            .ss{
                font-size: 13px;
                width: 70px;
                height: 30px;
                line-height: 30px;
                border: 1px solid rgb(200, 200, 201);
                padding-right: 10px;
                text-align: right;
                position: relative;
                margin-right: 15px;
                .sss{
                    position: absolute;
                    top: 5px;
                    border: solid 8px;
                    border-color: rgb(255, 254, 254) rgb(247, 246, 246) rgb(255, 254, 254) rgb(158, 157, 157);
                }
            }
        }
    }
    .btn{
        margin-top: 20px;
        padding: 0 15px;
        .mint-button{
            background-color: rgb(248, 143, 24);
            opacity: 0.5;
        }
        .btn-active{
            opacity: 1;
        }
    }
}
</style>
